package gunfire.cards;

import basemod.abstracts.CustomCard;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.DamageAction;
import com.megacrit.cardcrawl.actions.utility.WaitAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import gunfire.GunfireMod;
import gunfire.characters.Taizi;

import static gunfire.GunfireMod.makeCardPath;

public class WheelSaw extends CustomCard {

    public static final String ID = GunfireMod.makeID(WheelSaw.class.getSimpleName());
    private static final CardStrings cardStrings = CardCrawlGame.languagePack.getCardStrings(ID);
    public static final String NAME = cardStrings.NAME;
    public static final String DESCRIPTION = cardStrings.DESCRIPTION;
    public static final String IMG = makeCardPath("WheelSaw.png");
    private static final CardRarity RARITY = CardRarity.COMMON;
    private static final CardType TYPE = CardType.ATTACK;
    private static final CardTarget TARGET = CardTarget.ALL_ENEMY;
    public static final CardColor COLOR = Taizi.Enums.COLOR_GRAY;
    private static final int COST = 1;

    public WheelSaw() {
        super(ID, NAME, IMG, COST, DESCRIPTION, TYPE, COLOR, RARITY, TARGET);
        this.baseDamage = 4;
    }

    @Override
    public void upgrade() {
        if (!this.upgraded) {
            this.upgradeName();
            this.upgradeDamage(2);
        }
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {
        int damage = this.damage;
        final AbstractMonster[] mons = new AbstractMonster[2];
        this.addToBot(new AbstractGameAction() {
            @Override
            public void update() {
                mons[0] = AbstractDungeon.getRandomMonster();
                //这里必须是top，否则下一个目标可能会选到被第一下打死的
                this.addToTop(new DamageAction(mons[0], new DamageInfo(p, damage, DamageInfo.DamageType.NORMAL), AbstractGameAction.AttackEffect.SLASH_HORIZONTAL));
                this.isDone = true;
            }
        });
        this.addToBot(new AbstractGameAction() {
            @Override
            public void update() {
                mons[1] = AbstractDungeon.getRandomMonster();
                this.addToTop(new DamageAction(mons[1], new DamageInfo(p, damage, DamageInfo.DamageType.NORMAL), AbstractGameAction.AttackEffect.SLASH_HORIZONTAL));
                this.isDone = true;
            }
        });
        this.addToBot(new AbstractGameAction() {
            @Override
            public void update() {
                if(mons[0] == mons[1]){
                    this.addToBot(new DamageAction(mons[0], new DamageInfo(p, damage, DamageInfo.DamageType.NORMAL), AbstractGameAction.AttackEffect.SLASH_HORIZONTAL));
                }
                this.isDone = true;
            }
        });
    }

    @Override
    public AbstractCard makeCopy() {
        return new WheelSaw();
    }
}
